#include <bits/stdc++.h>
using namespace std;
using uint=unsigned int;
using ll=long long;
using ull=unsigned long long;
using i128=__int128;
const int N=1e6+5;

void solve(){
    int n,s;
    cin>>n>>s;
    vector<int> v(n);
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    if(s>v[n-1]){
        cout<<s-v[0]<<endl;
        return;
    }
    else if(s<v[0]){
        cout<<v[n-1]-s<<endl;
        return;
    }
    else{
        int l=abs(s-v[0]);
        int r=abs(s-v[n-1]);
        if(l>r){
            cout<<(v[n-1]-s)*2+s-v[0]<<endl;
            return;
        }
        else{
            cout<<(s-v[0])*2+v[n-1]-s<<endl;
            return;
        }
    }
    return;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t;
    cin>>t;
    while(t--)solve();
    

    return 0;
}